
var webpack = require('webpack');
var path = require('path');

// 单独打包插件
var ExtractTextPlugin = require("extract-text-webpack-plugin")
// 热服务器插件
//var BrowserSyncPlugin = require("browser-sync-webpack-plugin")
// 拷贝插件
//var CopyWebpackPlugin = require("copy-webpack-plugin")
// 多页面公共模块
//var commonsPlugin = new webpack.optimize.CommonsChunkPlugin('common.js')

module.exports = {

// 插件
    plugins: [
        new ExtractTextPlugin("[name].css"),
        // new BrowserSyncPlugin({
        //       server : './dist',
        //       port: 80,
        // }),
        // 文件拷贝        
        // new CopyWebpackPlugin([{
        //     from : './dist/',
        //     to : path.resolve(__dirname, '../VShop/www/static/admin'),
        //     force : true,
        //     flatten : true,
        //     ignore : 'index.html'

        // }]),
    ],
    // externals: {
    //     'vue': 'window.Vue',
    // },
// 入口文件
    entry  : {
        app  : './src/app.js'
    },

// 输出文件
    output :{
        path: './dist/',
        filename: '[name].js',
    },
    resolve: {
        alias : {
            'vue' : 'vue/dist/vue.js'
        }
    },
// 加载器配置
    module: {
        loaders: [
            {test: /\.js$/,    loader: "babel", query: {presets: ['es2015']}},
            {test: /\.css$/,   loader: ExtractTextPlugin.extract("style-loader", "css-loader")},            
            {test: /\.less$/,  loader: ExtractTextPlugin.extract("style-loader", "css!autoprefixer!less")},
            {test: /\.scss$/,  loader: ExtractTextPlugin.extract("style-loader", "css!autoprefixer!sass")},
            {test: /\.json$/,  loader: 'json'},
            {test: /\.vue$/,   loader: 'vue'},
            {test: /\.(gif|jpg|png|woff|svg|eot|ttf)\??.*$/, loader: 'url-loader?limit=50000&name=[path][name].[ext]'},
        ],
    },
    vue: {
      loaders: {
        //js : 'babel',
        css:    ExtractTextPlugin.extract('vue-style-loader', 'css'),
        less:   ExtractTextPlugin.extract('vue-style-loader', 'css!autoprefixer!less'),
        sass:   ExtractTextPlugin.extract('vue-style-loader', 'css!autoprefixer!sass'),
      }
    },
};

  // function generateExtractLoaders (loaders) {
  //   return loaders.map(function (loader) {
  //     return loader + '-loader' + (SOURCE_MAP ? '?sourceMap' : '')
  //   }).join('!')
  // }